package com.java.tutorials.jdk7.fileoperation;

import com.java.tutorials.Constants;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * Created by xuzhike on 2016/1/25.
 * http://www.java2s.com/Code/Java/JDK-7/Createtempfileanddirectory.htm
 * Create temp file and directory
 */
public class Createtempfileanddirectory {
    public static void main(String[] args) throws Exception {

        Path rootDirectory = FileSystems.getDefault().getPath(Constants.TEST_PATH);

        Path tempDirectory = Files.createTempDirectory(rootDirectory, "");
        System.out.println("Temporary directory created successfully!");
        String dirPath = tempDirectory.toString();
        System.out.println(dirPath);
        Path tempFile = Files.createTempFile(tempDirectory, "", "");
        System.out.println("Temporary file created successfully!");
        String filePath = tempFile.toString();
        System.out.println(filePath);
    }
}
